﻿@using QuestionsAnswers.UI.Models
@model IEnumerable<QuestionsAnswers.UI.Models.Question>
@if (Model.Any())
{
    <table>
        <tr>
            <th>
                Rating
            </th>
            <th>
                Answers
            </th>
            <th>
                Text
            </th>
        </tr>
        @foreach (var item in Model)
        { 
           
            <tr>
                <td>@Html.Partial("RatingsPartial", new RateModel { Id = item.QuestionId, Type = "Question", ReturnUrl = Request.Url.ToString(), Rating = item.QuestionRating })
                </td>
                <td>
                    @Html.ActionLink(item.Answers.Count.ToString(), "Index", "Answer", new { id = item.QuestionId }, null)
                </td>
                <td style="padding-top: 20px; text-align: left">
                    @Html.ActionLink(item.Text, "Index", "Answer", new { id = item.QuestionId }, new { style = "text-decoration:none" })
                    <p>
                    
                    <span style="text-align: left;float:left" >
                    Tags:
                    @foreach (Tag s in item.Tags)
                    {
                       @:@s.Name,
                    }
                    </span>
                    <span style="text-align: right;float:right">
                        @Html.DisplayFor(modelItem => item.User.UserName)|
                        
                        @if (User.Identity.Name == item.User.UserName)
                        {
                            @Ajax.ActionLink("Edit", "Edit", "Question", new { id = item.QuestionId }, new AjaxOptions { OnSuccess = "OnSuccessCreate" })  @:|                          
                            @Html.ConfirmLink("Delete", "Question", "Delete", new { id = item.QuestionId }, "Really Delete?") @:|                                                   
                        }
                       @* @Html.ActionLink("Assign To Course/Users", "ModifyCourseUsers", "Question", new { id = item.QuestionId }, null)*@
                        </span>
                    </p>
                </td>
            </tr>
            <tr>
                <td colspan="10">
                    <div class="expand">
                        Show Answers&nbsp;&nbsp;&nbsp;</div>
                    <div class="collapse">
                        @Html.Partial("Answers", item.Answers, new ViewDataDictionary { { "QuestionId", item.QuestionId } })
                        <br />
                        <hr />
                    </div>
                </td>
            </tr>           
        }
    </table>
}
else
{
    @:<p>There are currently no Questions</p>
}
